import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

let defaultCity = "上海";
try {
  if (localStorage.city) {
    defaultCity = localStorage.city;
  }
} catch (e) {
  console.log(e);
}

export default new Vuex.Store({
  state: {
    city: defaultCity
  },
  mutations: {
    changeCities(state, city) {
      state.city = city;
      try {
        localStorage.city = city;
      } catch (e) {
        console.log(e);
      }
    }
  },
  actions: {
    changeCity(ctx, city) {
      ctx.commit("changeCities", city);
    }
  },
  modules: {}
});
